package com.ruoyi.hr.controller.hr.contractmanage;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.contractmanage.NewSignService;
import com.ruoyi.hr.service.contractmanage.RelieveContractService;
import com.ruoyi.hr.service.contractmanage.StopContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zeo
 * @explain 合同解除登记
 * @date 2020/3/25
 */
@Controller
@RequestMapping("/contractManage/relieveContract")
public class RelieveContractController extends BaseController {

    @Autowired
    AuthorityService authorityService;

    @Autowired
    NewSignService newSignService;

    @Autowired
    RelieveContractService relieveContractService;

    private String prefix = "hr/contractmanage/relieve";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String relieveContract() {
        return prefix + "/relieveContract";
    }

    @RequestMapping("/findDataList")
    @ResponseBody
    public TableDataInfo findDataList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(relieveContractService.findDataList(map, authority));
    }

    @GetMapping("/addEmp")
    public String addEmp() {
        return prefix + "/addEmp";
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Map map = relieveContractService.findDataById(id);
        mmap.put("emp", map);
        return prefix + "/edit";
    }


    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(relieveContractService.edit(map));
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(relieveContractService.remove(ids));
    }
}
